package com.kai.steering.data.service.entity.domainObject;

import cn.hutool.core.bean.BeanUtil;
import com.kai.steering.data.service.entity.dto.UserQueryDTO;
import com.kai.steering.data.service.entity.dto.WarehouseDTO;
import com.kai.steering.data.service.entity.dto.WarehouseQueryDTO;
import com.kai.steering.data.service.entity.po.Test;
import com.kai.steering.data.service.entity.po.Warehouse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.*;

import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.stream.Collectors;

/**
 * <pre>
 * 仓库 DO对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "WarehouseDO对象", description = "仓库业务实体")
public class WarehouseDO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "仓库id")
    private String warehouseId;
    @ApiModelProperty(value = "仓库名")
    private String warehouseName;
    @ApiModelProperty(value = "上级仓库")
    private String warehouseSuperior;
    @ApiModelProperty(value = "仓库信息")
    private String warehouseInformation;
    @ApiModelProperty(value = "创建时间")
    private Date creationDatetime;
    @ApiModelProperty(value = "管理员id或者用户id")
    private String founder;
    @ApiModelProperty(value = "级别")
    private Integer level;
    @ApiModelProperty(value = "存在0删除1")
    private Integer usable;
    @ApiModelProperty(value = "删除日期")
    private Date deleteDatetime;

    @ApiModelProperty(value = "下级仓库")
    private List<WarehouseDO> childWarehouses;
    @ApiModelProperty(value = "知识点分类")
    private List<KnowledgeDO> knowledges;
    @ApiModelProperty(value = "试卷")
    private List<TestDO> testS;


    public WarehouseDO(String warehouseName, String warehouseInformation, Date creationDatetime, Integer level) {
        this.warehouseName = warehouseName;
        this.warehouseInformation = warehouseInformation;
        this.creationDatetime = creationDatetime;
        this.level = level;
    }

    public WarehouseDO(Warehouse warehouse) {
        this.convertWarehouseDO(warehouse);
    }

    public WarehouseDO(WarehouseQueryDTO warehouseQueryDTO) {
        this.convertWarehouseDO(warehouseQueryDTO);
    }

    public WarehouseDO(WarehouseDTO warehouseDTO) {
        this.convertWarehouseDO(warehouseDTO);
    }

    public WarehouseDO(String id) {
        this.warehouseId=id;
    }

    /**
     * 转po为do
     *
     * @param warehouse
     * @return
     */
    public WarehouseDO convertWarehouseDO(Warehouse warehouse) {
        if (warehouse==null) {
            return null;
        }
        this.warehouseId = warehouse.getWarehouseId();
        this.warehouseName = warehouse.getWarehouseName();
        this.warehouseSuperior = warehouse.getWarehouseSuperior();
        this.warehouseInformation = warehouse.getWarehouseInformation();
        this.creationDatetime = warehouse.getCreationDatetime();
        this.founder = warehouse.getFounder();
        this.level = warehouse.getLevel();
        this.usable = warehouse.getUsable();
        this.deleteDatetime = warehouse.getDeleteDatetime();

        return this;
    }

    /**
     * 转WarehouseQueryDTO为do
     *
     * @param warehouseQueryDTO
     * @return
     */
    public WarehouseDO convertWarehouseDO(WarehouseQueryDTO warehouseQueryDTO) {
        this.warehouseId = warehouseQueryDTO.getWarehouseId();
        this.warehouseName = warehouseQueryDTO.getWarehouseName();
        this.warehouseSuperior = warehouseQueryDTO.getWarehouseSuperior();
        this.warehouseInformation = warehouseQueryDTO.getWarehouseInformation();
        this.creationDatetime = null;
        this.founder = warehouseQueryDTO.getFounder();
        this.level = warehouseQueryDTO.getLevel();
        this.deleteDatetime = null;


        this.childWarehouses=null;

        this.knowledges= Arrays.stream(warehouseQueryDTO.getKnowledges()).map(s -> {
            return new KnowledgeDO(s);
        }).collect(Collectors.toList());

        return this;
    }
    /**
     * 转QueryDTO为do
     *
     * @param warehouseDTO
     * @return
     */
    public WarehouseDO convertWarehouseDO(WarehouseDTO warehouseDTO){
        this.warehouseId = warehouseDTO.getWarehouseId();
        this.warehouseName = warehouseDTO.getWarehouseName();
        this.warehouseSuperior = warehouseDTO.getWarehouseSuperior();
        this.warehouseInformation = warehouseDTO.getWarehouseInformation();
        this.creationDatetime = warehouseDTO.getCreationDatetime();
        this.founder = warehouseDTO.getFounder();
        this.level = warehouseDTO.getLevel();
        this.deleteDatetime = null;


        this.childWarehouses=null;

        if (warehouseDTO.getKnowledges()!=null) {
            this.knowledges= Arrays.stream(warehouseDTO.getKnowledges()).map(s -> {
                return new KnowledgeDO(s);
            }).collect(Collectors.toList());
        }


        return this;
    }
}